/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.chassis.customgrid;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JCheckBox;

import twaver.Element;
import twaver.MovableFilter;
import twaver.ResizableFilter;
import twaver.TDataBox;
import twaver.network.TNetwork;
import demo.DemoPane;

public class CustomGridDemo extends DemoPane {
	TDataBox box = new TDataBox();
	TNetwork network = new TNetwork(box);
	JCheckBox editMode = new JCheckBox("Edit Mode", true);
	
	public CustomGridDemo(){		
		this.add(network, BorderLayout.CENTER);

		network.getToolbar().addSeparator();
		network.getToolbar().add(editMode);
		network.putClientProperty("Edit Mode", Boolean.valueOf(editMode.isSelected()));
		editMode.addActionListener(new ActionListener(){
			public void actionPerformed(ActionEvent e) {
				network.putClientProperty("Edit Mode", Boolean.valueOf(editMode.isSelected()));
				network.getCanvas().repaint();
			}
		});
		network.setResizableFilter(new ResizableFilter(){
			public boolean isResizable(Element element) {
				return Boolean.TRUE.equals(network.getClientProperty("Edit Mode"));
			}
		});
		network.setMovableFilter(new MovableFilter(){
			public boolean isMovable(Element element) {
				return Boolean.TRUE.equals(network.getClientProperty("Edit Mode"));
			}
		});
		
		CustomGrid grid = new CustomGrid();
		grid.setRowCount(6);
		grid.setColumnCount(20);
		grid.setSize(600, 300);
		grid.setLocation(60, 60);
		box.addElement(grid);
		
		for(int row=0; row<grid.getRowCount(); row++){
			for(int column=0; column<grid.getColumnCount(); column++){
				Cell card = new Cell();
				card.setName(row + "-" + column);
				card.setRowIndex(row);
				card.setColumnIndex(column);
				card.setHost(grid);
				box.addElement(card);
			}
		}
		
		network.setSelectionMode(TNetwork.CONTAIN_SELECTION);
		

	}
}